<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店长" prop="shopUser">
        <el-input
          v-model="queryParams.shopUser"
          placeholder="请输入店长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺类型" prop="shopType">
        <el-select v-model="queryParams.shopType" placeholder="请选择店铺类型" clearable>
          <el-option
            v-for="dict in dict.type.prod_shop_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="店铺状态" prop="shopStatus">
        <el-select v-model="queryParams.shopStatus" placeholder="请选择店铺状态" clearable>
          <el-option
            v-for="dict in dict.type.prod_shop_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否自营" prop="isSelf">
        <el-select v-model="queryParams.isSelf" placeholder="请选择是否自营" clearable>
          <el-option
            v-for="dict in dict.type.store_check_is_self"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['shop:shop:add']"
              >新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['shop:shop:edit']"
              >修改</el-button>
            </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['shop:shop:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['shop:shop:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="shopList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="ID" align="center" prop="shopsId"/>
      <el-table-column label="店铺名称" align="center" prop="shopName"/>
      <el-table-column label="店长" align="center" prop="shopUser"/>
      <el-table-column label="店铺logo" align="center" prop="shopLogo" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.shopLogo" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="店铺类型" align="center" prop="shopType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.prod_shop_type" :value="scope.row.shopType"/>
        </template>
      </el-table-column>
      <el-table-column label="店铺状态" align="center" prop="shopStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.prod_shop_status" :value="scope.row.shopStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="是否自营" align="center" prop="isSelf">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.store_check_is_self" :value="scope.row.isSelf"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['shop:shop:edit']"
          >店铺详细
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['shop:shop:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看店铺详细列表对话框 -->
    <div class="dialog-container">
    <el-dialog :title="title" :visible.sync="open" width="100%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <div style="float: left">
            <el-form-item label="店铺名称" prop="shopName">
              <el-input v-model="form.shopName" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="店长" prop="shopUser">
              <el-input v-model="form.shopUser" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="店铺logo" prop="shopLogo">
              <image-upload v-model="form.shopLogo"/>
            </el-form-item>
            <el-form-item label="店铺地址" prop="shopUrl">
              <el-input v-model="form.shopUrl" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="详细地址" prop="shopAddress">
              <el-input v-model="form.shopAddress" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="店铺类型" prop="shopType">
              <el-select v-model="form.shopType" placeholder="请选择店铺类型">
                <el-option
                  v-for="dict in dict.type.prod_shop_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="店铺状态" prop="shopStatus">
              <el-select v-model="form.shopStatus" placeholder="请选择店铺状态">
                <el-option
                  v-for="dict in dict.type.prod_shop_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否自营" prop="isSelf">
              <el-select v-model="form.isSelf" placeholder="请选择是否自营">
                <el-option
                  v-for="dict in dict.type.store_check_is_self"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="店铺联系人" prop="shopPhone">
              <el-input v-model="form.shopPhone" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="电子邮件" prop="shopEmail">
              <el-input v-model="form.shopEmail" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="审核通过时间" prop="shopApprovedAt">
              <el-input v-model="form.shopApprovedAt" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="店铺申请编号" prop="applyId">
              <el-input v-model="form.applyId" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="订单编号" prop="orderId">
              <el-input v-model="form.orderId" placeholder="请输入订单编号" style="width: 200px"/>
            </el-form-item>
            <el-form-item label="营业时间" prop="openingHours">
              <el-input v-model="form.openingHours" placeholder="请输入营业时间" style="width: 200px"/>
            </el-form-item>
            <el-form-item label="营业执照" prop="shopLicense">
              <image-upload v-model="form.shopLicense"/>
            </el-form-item>
          </div>
          <div style="float: left;margin-left: 100px;">
            <el-form-item label="店铺规模" prop="shopSize">
              <el-select v-model="form.shopSize" placeholder="请选择店铺规模">
                <el-option
                  v-for="dict in dict.type.store_apply_store_size"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="主营产品" prop="mainProducts">
              <el-input v-model="form.mainProducts" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="副营产品" prop="otherProducts">
              <el-input v-model="form.otherProducts" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="店铺描述:" prop="shopDescription">
              <el-input v-model="form.shopDescription" type="textarea" :autosize="true"/>
            </el-form-item>
            <el-form-item label="店铺门面:" prop="shopFacade">
              <image-upload v-model="form.shopFacade"/>
            </el-form-item>
            <el-form-item label="店铺简介" prop="shopIntroduction">
              <el-input v-model="form.shopIntroduction" type="textarea" :autosize="true"/>
            </el-form-item>
            <el-form-item label="银行开户名" prop="bankAccountName">
              <el-input v-model="form.bankAccountName" style="width: 200px"/>
            </el-form-item>
            <el-form-item label="银行账号" prop="bankAccount">
              <el-input v-model="form.bankAccount" style="width: 200px"/>
            </el-form-item>
            <el-form-item label="开户行支行名称" prop="subBranch">
              <el-input v-model="form.subBranch" style="width: 200px"/>
            </el-form-item>
            <el-form-item label="支行联行号" prop="lineNumber">
              <el-input v-model="form.lineNumber" style="width: 200px"/>
            </el-form-item>
          </div>
          <div style="float: left;margin-left: 100px;">
            <el-form-item label="法人姓名" prop="legalPersonName">
              <el-input v-model="form.legalPersonName" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="法人证件号" prop="legalPersonDocument">
              <el-input v-model="form.legalPersonDocument" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="法人身份证照片" prop="legalPersonImage">
              <image-upload v-model="form.legalPersonImage"/>
            </el-form-item>
            <el-form-item label="公司名称" prop="corporateName">
              <el-input v-model="form.corporateName" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="公司电话" prop="corporatePhone">
              <el-input v-model="form.corporatePhone" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="公司所在地" prop="corporateUrl">
              <el-input v-model="form.corporateUrl" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="公司详细地址" prop="corporateAddress">
              <el-input v-model="form.corporateAddress" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="员工总数" prop="corporateCount">
              <el-input v-model="form.corporateCount" style="width: 100px" :disabled="true"/>
              人
            </el-form-item>
            <el-form-item label="注册资金" prop="registeredCapital">
              <el-input v-model="form.registeredCapital" style="width: 100px" :disabled="true"/>
              万元
            </el-form-item>
            <el-form-item label="联系人姓名" prop="contactName">
              <el-input v-model="form.contactName" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="联系人手机" prop="contactPhone">
              <el-input v-model="form.contactPhone" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="电子邮箱" prop="contactEmail">
              <el-input v-model="form.contactEmail" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="营业执照号" prop="licenseNumber">
              <el-input v-model="form.licenseNumber" style="width: 200px" :disabled="true"/>
            </el-form-item>
            <el-form-item label="法定经营范围" prop="businessScope">
              <el-input v-model="form.businessScope" type="textarea" :autosize="true" :disabled="true"/>
            </el-form-item>
            <el-form-item label="营业执照电子版" prop="shopELicense">
              <image-upload v-model="form.shopELicense"/>
            </el-form-item>
          </div>
          <div class="rejectReason">
            <el-form-item label="驳回理由" prop="rejectReason">
              <el-input v-model="form.rejectReason" type="textarea" style="width: 200px;" :disabled="true"/>
            </el-form-item>
          </div>
        </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
  </div>
</template>

<script>
import {listShop, getShop, delShop, addShop, updateShop} from "@/api/shop/shop";

export default {
  name: "Shop",
  dicts: ['store_apply_store_size', 'prod_shop_status', 'store_check_is_self', 'prod_shop_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺列表表格数据
      shopList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopName: null,
        shopUser: null,
        shopLogo: null,
        shopType: null,
        shopStatus: null,
        isSelf: null,
        orderByColumn:'shop_approved_at',
        isAsc:'asc',
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询店铺列表列表 */
    getList() {
      this.loading = true;
      listShop(this.queryParams).then(response => {
        this.shopList = response.rows;
        console.info(this.shopList)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        shopsId: null,
        shopName: null,
        shopUser: null,
        shopLogo: null,
        shopUrl: null,
        shopAddress: null,
        shopType: null,
        shopStatus: null,
        isSelf: null,
        shopPhone: null,
        shopEmail: null,
        shopApprovedAt: null,
        applyId: null,
        orderId: null,
        openingHours: null,
        shopLicense: null,
        shopSize: null,
        mainProducts: null,
        otherProducts: null,
        shopApprovedBy: null,
        shopDescription: null,
        shopFacade: null,
        shopIntroduction: null,
        createTime: null,
        updateTime: null,
        bankAccountName: null,
        bankAccount: null,
        subBranch: null,
        lineNumber: null,
        legalPersonName: null,
        legalPersonDocument: null,
        legalPersonImage: null,
        corporateName: null,
        corporatePhone: null,
        corporateUrl: null,
        corporateAddress: null,
        corporateCount: null,
        registeredCapital: null,
        contactName: null,
        contactPhone: null,
        contactEmail: null,
        licenseNumber: null,
        businessScope: null,
        shopELicense: null,
        rejectReason: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.shopsId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加店铺列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const shopsId = row.shopsId || this.ids
      getShop(shopsId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "店铺详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.shopsId != null) {
            updateShop(this.form).then(response => {
              /*this.$modal.msgSuccess("");*/
              this.open = false;
              this.getList();
            });
          } else {
            addShop(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const shopsIds = row.shopsId || this.ids;
      this.$modal.confirm('是否确认删除店铺列表编号为"' + shopsIds + '"的数据项？').then(function () {
        return delShop(shopsIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('shop/shop/export', {
        ...this.queryParams
      }, `shop_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.dialog-container {
  display: flex;
  height: 100%;
}
.form-container {
  flex: 1;
}
.rejectReason{

}
</style>
